package hxg.面试题.test.jdk8新特性.函数;

/**
 * @author HeXiangGuang
 * @create 2022-10-21 10:44
 */


public class Function {

    //供给型函数
    @FunctionalInterface
    public interface Func<T> {
        T get();
    }

    public static class FuncImpl implements Func<Integer> {

        @Override
        public Integer get() {
            return 3;
        }
    }

    public static Integer getInteger(Func<Integer> func) {
        return func.get();
    }

    public static void testFunc(){
        //匿名内部类的方式
        System.out.println(getInteger(new Func<Integer>() {

            @Override
            public Integer get() {
                return 4;
            }
        }));
        //Lambda形式
        System.out.println(getInteger(() -> 5));
        //实现类的方式
        System.out.println(getInteger(new FuncImpl()));
    }

    public static void main(String[] args) {
        //测试Function
        testFunc();
    }
}


